package com.springboot.blog.controller;

import com.springboot.blog.beans.AdminUser;
import com.springboot.blog.beans.Permission;
import com.springboot.blog.beans.RoleName;
import com.springboot.blog.dao.AdminUserDao;
import com.springboot.blog.service.PermissionService;
import com.springboot.blog.service.RolesService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

//@CrossOrigin //解决跨域
@Controller
@RequestMapping("/role")
public class RolesController {

    @Resource
    private RolesService rolesService;
    @Resource
    private PermissionService permissionService;
    @Resource
    private AdminUserDao adminUserDao;

    @RequestMapping("findroleJueSe")
    public String  findroleJueSe(Model model){
        List<RoleName> roles = rolesService.selectAll();
        List<Permission> permissions = permissionService.selectPermission();
        model.addAttribute("roles",roles);
        model.addAttribute("permissions",permissions);
        return "admin/roleform";
    }

    @RequestMapping("findroleUser")
    public String  findroleUser(Model model){
        List<RoleName> roles = rolesService.selectAll();
        model.addAttribute("roles",roles);

        List<AdminUser> adminUsers = adminUserDao.selectList(null);
        model.addAttribute("adminUsers",adminUsers);
        return "admin/roleUserform";
    }

}
